package com.android.pagemarket.ui.widget;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.PopupWindow;

import com.android.pagemarket.R;
import com.android.pagemarket.util.ImageLoader;
import com.android.pagemarket.util.ImageLoader.Imager;

/*********************************************************
 * @author : zhaohua
 * @version : 2012-11-23
 * @see : 图片全屏弹出浏览原图
 * @Copyright : copyrights reserved by personal 2007-2011
 **********************************************************/
public class ImagePopWindow extends PopupWindow
{
    Context mContext;
    private ImageView image;
    
    public ImagePopWindow(Context context)
    {
        super(LayoutInflater.from(context)
                .inflate(R.layout.popview_image, null),LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        mContext = context;
        setBackgroundDrawable(new ColorDrawable(0x99000000));
        setTouchable(true);
        setFocusable(true);
        setOutsideTouchable(true); 
        initViews();
    }
    
    private void initViews()
    {
        View v = getContentView();
        image = (ImageView)v.findViewById(R.id.image);
        
        v.findViewById(R.id.close).setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                dismiss();
            }
        });
    }
    
    public void setImageResource(int resId)
    {
        image.setImageResource(resId);
    }
    
    public void setImageUrl(Uri uri)
    {
        image.setImageURI(uri);
    }
    
    public void setImageUrl(String url)
    {
        ImageLoader.getInstance().DisplayImage(new Imager(url, image, 0, R.drawable.ic_pic_default));
    }
}
